package com.ict.web.dto;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.constant.Constants;
import com.ict.web.constant.ProjectStatusEnum;
import com.ict.web.domain.ExtractExpert;
import com.ict.web.domain.ReviewTask;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 评审任务对象 yzq_review_task
 *
 * @author ruoyi
 * @date 2022-02-16
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class InsertReviewTaskDto {

    /** 项目id */
    @ApiModelProperty(value = "项目id")
    private Long proId;

    /** 年度计划id */
    @ApiModelProperty(value = "年度计划id")
    private Long planId;

    /** 任务名称 */
    @ApiModelProperty(value = "任务名称")
    @NotBlank(message = "任务名称不能为空")
    private String taskName;

    /** 评审类型 */
    @ApiModelProperty(value = "评审类型(0:方案评审 1：年度项目清单评审")
    @NotBlank(message = "评审类型不能为空")
    private String reviewType;

    /** 评审开始时间 */
    @ApiModelProperty(value = "评审开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
    @NotNull(message = "评审开始时间不能为空")
    private LocalDateTime reviewTimeStart;

    /** 评审结束时间 */
    @ApiModelProperty(value = "评审结束时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
    private LocalDateTime reviewTimeEnd;

    /** 评审地点 */
    @ApiModelProperty(value = "评审地点")
    @NotBlank(message = "评审地点不能为空")
    private String reviewAddress;

    /** 专家数量 */
    @ApiModelProperty(value = "专家数量")
    @NotBlank(message = "专家数量不能为空")
    private String expertNum;


    /** 抽取的专家信息list*/
    @ApiModelProperty(value = "专家信息list")
    @NotNull(message = "抽取的专家信息list不能为空")
    private List<ExtractRuleDto> expertList;
    /**
     * InsertReviewTaskDto 转化为 ReviewTask
     *
     * @param dto 评审任务dto
     * @return ReviewTask
     */
    public static ReviewTask toReviewTask(InsertReviewTaskDto dto) {
        ReviewTask bean = new ReviewTask();
        BeanUtils.copyProperties(dto, bean);
        bean.setReviewTaskId(IdUtils.snowId());
        bean.setIfExchangeThird(ReviewTask.IF_EXCHANGE_THIRD_NO);
        bean.setNode(ProjectStatusEnum.ACCEPT_NOT_TASK.get().getNode());
        bean.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_ACCEPT);
        bean.setExtractType(ReviewTask.EXTRACT_TYPE_UNIFY);
        bean.setExtractTime(LocalDateTime.now());
        bean.setNodeStatus(Constants.ARRANGE_REVIEW_MEETING_BAND_EXTRACTION);
        bean.setExtractResult(ReviewTask.EXTRACT_RESULT_SEND_EXPERT);
        //抽取单位
        bean.setExtractUnit(String.valueOf(SecurityUtils.getDeptId()));
        //抽取操作人
        bean.setExtractPeople(SecurityUtils.getNickName());
        bean.setCreateTime(LocalDateTime.now());
        bean.setDelFlag(ExtractExpert.DELETE_STATUS_NORMAL);

        return bean;
    }
}
